﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TMDT_Nhom1A.DTO;

namespace TMDT_Nhom1A.DAO
{
    public class Statistic_DAO
    {
        private static QL_DoanhNghiepDataContext data = new QL_DoanhNghiepDataContext();
        public static string calculateTransactionStatistic()
        {
            try
            {
                string result = "";
                data.sp_CalculateTransactionStatistic(ref result);

                return result;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public static void CalculateMonthlyAndQuaterRevenue(ref string monthlyRevenue, ref string quaterRevenue)
        {
            try
            {                
                data.sp_CalculateMonthlyAndQuaterRevenue(ref monthlyRevenue,ref quaterRevenue);               
            }
            catch (Exception ex)
            {
                return ;
            }
        }

        public static string calculateRevenueByCatalogue(ref string parentCatalogue)
        {
            try
            {
                string str = "";
                //lay ra cac ID cua parentCatalogue
                var parentCatalogueResult = from cal in data.PARENT_CATALOGUEs
                                            select cal;

                if (parentCatalogueResult.Count() >= 1)
                {
                    foreach (var parentCaltogueItem in parentCatalogueResult)
                    {
                        parentCatalogue += parentCaltogueItem.ParentCatalogue_Name + ",";
                        string cost = "";
                        data.sp_CalculateRevenueByCatologue(parentCaltogueItem.ParentCatalogue_ID, ref cost);
                        str += cost + ",";
                    }
                }
                parentCatalogue = parentCatalogue.Remove(parentCatalogue.Length - 1);
                str = str.Remove(str.Length - 1);

                return str;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public static void CalculateYearlyRevenue(ref string xData, ref string yearly)
        {
            try
            {
                data.sp_CalculateYearlyRevenue(ref xData,ref yearly);
            }
            catch (Exception ex)
            {
                return;
            }
        }
    }
}
